package com.dcits.account.controller;

import com.dcits.account.entity.cto.InputObject;
import com.dcits.account.entity.cto.OutputObject;
import com.dcits.account.entity.po.UserEntity;
import com.dcits.account.service.interfaces.IBillService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

/**
 * @Auther: 2843896844@qq.com
 * @Date: 2021/06/11/19:52
 * @Description:
 */
@Controller
public class BillController {

    private Logger logger = LoggerFactory.getLogger(BillController.class);

    @Autowired
    private IBillService iBillService;

    @ResponseBody
    @GetMapping(value = "/bill/list")
    public OutputObject getBillListByPage(
            @RequestParam(value = "pageNum", required = false, defaultValue = "1") Integer pageNum,
            @RequestParam(value = "pageSize", required = false, defaultValue = "10") Integer pageSize,
            @RequestHeader(value = "keyword", required = false, defaultValue = "") String keyword
    ) {
        InputObject inputObject = new InputObject();
        OutputObject outputObject = new OutputObject();
        inputObject.put("pageNum", pageNum);
        inputObject.put("pageSize", pageSize);
        inputObject.put("keyword", keyword);
        iBillService.getBillListByPage(inputObject, outputObject);
        return outputObject;
    }

    @ResponseBody
    @GetMapping(value = "/get/line/data")
    public OutputObject getLineData(HttpServletRequest request) {
        HttpSession session = request.getSession();
        UserEntity user = (UserEntity) session.getAttribute("user");
        InputObject inputObject = new InputObject();
        OutputObject outputObject = new OutputObject();
        inputObject.getParams().put("user", user);
        iBillService.getLineData(inputObject, outputObject);
        return outputObject;
    }
}
